<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>召唤神龙</title>
  <meta name="viewport"
        content="width=device-width,user-scalable=no,initial-scale=1, minimum-scale=1,maximum-scale=1"/>
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
  <meta name="format-detection" content="telephone=no">
  <!-- force webkit on 360 -->
  <meta name="renderer" content="webkit"/>
  <meta name="force-rendering" content="webkit"/>
  <!-- force edge on IE -->
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
  <meta name="msapplication-tap-highlight" content="no">
  <!-- force full screen on some browser -->
  <meta name="full-screen" content="yes"/>
  <meta name="x5-fullscreen" content="true"/>
  <meta name="360-fullscreen" content="true"/>
  <!-- force screen orientation on some browser -->
  <meta name="screen-orientation" content=""/>
  <meta name="x5-orientation" content="">
  <meta name="x5-page-mode" content="app">
  <link rel="stylesheet" type="text/css" href="./css/style-mobile.css"/>
  <script src="./../../../base/bmob/bmob.js"></script>
</head>
<script>
  window.Timer = new class {
    constructor() {
      this.second = 0;
      this.history = null;
      this.div = null;
      this.id = null;
      this.init();
    }
    updateLastScore(name,score) {
      this.history.innerText = `${name} : ${score / 10} s`;
    }
    init() {
      this.history = document.createElement('div');
      this.history.style.position = 'absolute';
      this.history.style.top = '5px';
      this.history.style.right = '5px';
      this.div = document.createElement('div');
      this.div.innerText = '';
      this.div.style.position = 'absolute';
      this.div.style.top = '5px';
      this.div.style.left = '5px';
      this.id = setInterval(() => {
        this.second += 1;
        this.div.innerText = `${this.second / 10} s`;
      },100);
      let _id = setInterval(() => {
        if (window.document.body) {
          document.body.appendChild(this.div);
          document.body.appendChild(this.history);
          clearInterval(_id);
          this.reset();
        }
      },500);
    }
    reset() {
      this.second = 0;
    }
    getSecond() {
      return this.second;
    }
  }
  Bmob.initialize('693f7e27f97550ba','IBAS12');
  Bmob.User.login('ibas','ibas').then(console.log);
  window.Record = new class {
    constructor() {
      this.record = Bmob.Query('score');
      this.name = `name_${parseInt(Math.random() * 100)}_${new Date().getTime()}`;
      this.score = -1;
      this.id = null;
    }
    setName(name) {
      name = name.toString();
      if (name !== '') {
        this.name = name;
      }
    }
    add(name,score,over) {
      this.record.set('name',name || this.name);
      this.record.set('score',score.toString());
      this.record.set('over',over ? 'T':'F');
      if (over) {
        if (this.score === -1) {
          this.score = score;
        } else if (this.score > score) {
          this.score = score;
        }
        window.Timer.updateLastScore(this.name,this.score);
      }
      return this.record.save().then(obj => {
        this.id = obj.objectId;
        return obj;
      });
    }
    getByName(name) {
      this.record.equalTo("name","==", name || this.name);
      return this.record.find().then(res => {
        if (res.length) {
          this.score = res[0].over === 'T' ? +res[0].score : -1;
          this.id = res[0].objectId;
          window.Timer.updateLastScore(this.name,this.score);
        }
        return res;
      });
    }
    update(score,over) {
      if (this.id) {
        this.record.set('id',this.id);
        return this.add('',score,over);
      } else {
        return this.add('',score,over);
      }
    }
    getAll() {
      return this.record.find();
    }
  };
  if (localStorage.getItem('__name__')) {
    window.name = localStorage.getItem('__name__');
  } else {
    window.name = prompt('输入你的昵称',`name_${parseInt(Math.random() * 100)}_${new Date().getTime()}`);
  }
  window.Record.setName(window.name);
  localStorage.setItem('__name__',window.name);
  window.Record.getByName(window.name);

</script>
<canvas id="GameCanvas" oncontextmenu="event.preventDefault()" tabindex="0" ></canvas>
<div id="canvasDiv" style="width:100%;height:100%;">
</div>

<div id="loadingText"
     style="width:100%;display: none;text-align:center;position:absolute;top:45%;z-index:2;font-size:20px;color:#f99f0a">
  loading......0%
</div>

<div id="splash">
</div>

<div id="loadingImg" style="top:45%;width: 100%;position:absolute; ">
  <img src="./images/loading.gif" width="7%" height="7%" />
</div>

<!--<div align="center" style="font-size: 10px;color: dimgrey">advertisement</div>-->

<script type="text/javascript" src="http://imasdk.googleapis.com/js/sdkloader/ima3.js"></script>
<script src="./js/settings.js" charset="utf-8"></script>

<script type="text/javascript">
  function finishLoad(){
    setTimeout(function(){
      document.getElementById('loadingImg').remove();
    },0.1 * 1000);
  }
  const adBreak =  function(o) {}
</script>

<script src="./js/main.js" charset="utf-8"></script>
<script type="text/javascript">

  (function () {
    // open web debugger console
    if (typeof VConsole !== 'undefined') {
      window.vConsole = new VConsole();
    }

    var debug = window._CCSettings.debug;
    var splash = document.getElementById('splash');
    splash.style.display = 'block';

    function loadScript (moduleName, cb) {
      function scriptLoaded () {
        document.body.removeChild(domScript);
        domScript.removeEventListener('load', scriptLoaded, false);
        cb && cb();
      };
      var domScript = document.createElement('script');
      domScript.async = true;
      domScript.src = moduleName;
      domScript.addEventListener('load', scriptLoaded, false);
      document.body.appendChild(domScript);
    }

    loadScript(debug ? './js/cocos2d-js.js' : './js/cocos2d-js-min.js', function () {
      if (CC_PHYSICS_BUILTIN || CC_PHYSICS_CANNON) {
        loadScript(debug ? 'physics.js' : 'physics-min.js', window.boot);
      }
      else {
        window.boot();
      }
    });
  })();
  window.noAdGoToScene = function(){
    var GameConfig = __require("GameConfig");
    console.log("IndexMainMangerMaing",GameConfig.launchScene, GameConfig.Bros,GameConfig.caS);

    var launchScene = GameConfig.launchScene;
    var Bros = GameConfig.Bros;
    var caS = GameConfig.caS;
    cc.director.loadScene(launchScene, null,
            function () {
              adCompleteFlag = false;
              if (Bros) {
                // show canvas
                var canvas = document.getElementById('GameCanvas');
                canvas.style.visibility = '';
                var div = document.getElementById('GameDiv');
                if (div) {
                  div.style.backgroundImage = '';
                }
              }
              cc.loader.onProgress = null;
              console.log('Success to load scene1Main: ' + launchScene);
            }
    );
  }

</script>
</body>
</html>
